<?php

defined('BASEPATH') OR exit('No direct script access allowed');
/*
 * 处理上传文件类
 */

class Upload extends Base_Controller {
    //附件处理
    public function do_upload() {
        $redata = $this->httpcode;
        $config['upload_path'] = './uploads/mail_file/';
        $config['allowed_types'] = 'png|gif|jpg|jpeg|txt|xls|mp4|wav|xlsx';
        $config['file_name'] = date('YmdHis').'_'.$this->session->uid;
        $config['max_filename'] = 0;
        $this->load->library('upload', $config);
        if (!$this->upload->do_upload('file')) {
            $error = ['error' => $this->upload->display_errors()];
            $redata['errno'] = 600;
            $redata['error'] = $error;
        } else {
            $data = ['upload_data' => $this->upload->data()];
            $redata['errno'] = 666;
            $redata['error'] = '上传成功';
            $redata['uploadInfo'] = $data;
        }
        echo json_encode($redata);
    }
    //导入excel/txt联系人地址
    public function do_upload_address() {
        $redata = $this->httpcode;
        $config['upload_path'] = './uploads/address_file/';
        $config['allowed_types'] = 'txt|xls|xlsx';
        $config['file_name'] = date('YmdHis').'_'.$this->session->uid;
        $config['max_filename'] = 0;
        $this->load->library('upload', $config);

        if (!$this->upload->do_upload('file')) {
            $error = ['error' => $this->upload->display_errors()];
            $redata['errno'] = 600;
            $redata['error'] = $error;
        } else {
            $data = ['upload_data' => $this->upload->data()];
            $redata['errno'] = 666;
            $redata['error'] = '文件导入成功';
            $redata['uploadInfo'] = $data;
        }
        echo json_encode($redata);
    }
    
}
